package com.admin.scroller.photovideo

import android.app.Activity
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import com.admin.scroller.photoorvideo.PhotoChoseActivity
import com.bumptech.glide.Glide
import kotlinx.android.synthetic.main.activity_main.*
import java.io.File

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        iv_image.setOnClickListener {
            val intent=Intent(this, PhotoChoseActivity::class.java)
            intent.putExtra(PhotoChoseActivity.BODY_TYPE,PhotoChoseActivity.TYPE_GRILD)
            startActivityForResult(intent,100)
        }

        btn_chose.setOnClickListener {
            val intent=Intent(this,PhotoChoseActivity::class.java)
            intent.putExtra(PhotoChoseActivity.BODY_TYPE,PhotoChoseActivity.TYPE_LIST)
            startActivityForResult(intent,100)
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if(resultCode== Activity.RESULT_OK){
            when (requestCode){
                100->{
                    val images=data!!.getStringArrayListExtra(PhotoChoseActivity.RESULT_IMAGES)
                    Glide.with(this).load(File(images[0])).into(iv_image)
                    val s=StringBuffer()
                    for(i in images){
                        s.append(i).append("\n")
                    }
                    tv_result.text = s.toString()
                }
            }
        }
    }
}
